/*
Copyright (c) 2011, Nimar S. Arora
All rights reserved.
*/

#ifndef GRAPH_H
#define GRAPH_H

#define MAX_CARD 10000

typedef struct Variable_t
{
  int var_id;               /* a unique number assigned to each var */
  
  int var_card;                             /* variable cardinality */

  int var_num_facs;  /* number of factors which mention variable */
  struct Factor_t ** var_p_facs; /* array of factors which mention var */

} Variable_t;

typedef struct Factor_t
{
  int fac_id;            /* a unique number assigned to each factor */
  
  int fac_num_vars;               /* number of variables in factor */
  Variable_t ** fac_p_vars;         /* array of variables in factor */

  int fac_num_entries;                   /* number of table entries */
  double * fac_p_entries;                    /* the table entries */
  double * fac_p_log_entries;           /* the log of table entries */

} Factor_t;

typedef struct Graph_t
{
  int graph_num_vars;                        /* number of variables */
  Variable_t * graph_p_vars;                 /* array of variables */

  /* For a Bayes Network the factors refer to the CPDs. Hence the
   * number of factors equals the number of variables. The CPD of
   * variable i is factor i */
  
  int graph_num_facs;                        /* number of factors */
  Factor_t * graph_p_facs;                   /* array of factors */
  
} Graph_t;

typedef struct Instance_t
{
  int * inst_p_is_obs;
  int * inst_p_val;
} Instance_t;

double graph_factor(Factor_t * p_fac, int * p_var_vals);

double graph_joint_factor(Graph_t * p_graph, int * p_var_vals);

#endif  /* GRAPH_H */
